﻿' Note: For instructions on enabling IIS6 or IIS7 classic mode, 
' visit http://go.microsoft.com/?LinkId=9394802
Imports System.Data.Entity
Imports System.Data.Entity.Infrastructure
Imports System.Web.Optimization
Imports JertiFramework.Ruteo
Imports JertiFramework

Public Class MvcApplication
    Inherits System.Web.HttpApplication

    Shared Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection)
        filters.Add(New HandleErrorAttribute())
        filters.Add(New JFAutorizationSecurity())
    End Sub

    Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

        ' MapRoute takes the following parameters, in order:
        ' (1) Route name
        ' (2) URL with parameters
        ' (3) Parameter defaults

        routes.MapRoute("Route_RegistroAcademicoHome",
                        "RegistroAcademico/Inicio",
                        New With {.controller = "Periodos", .action = "Periodos_Eva", .topmenu = "Inicio"})

        'routes.MapRoute("Route_RegistroAcademico",
        '                "RegistroAcademico/{topmenu}/{controller}/{action}/{id}",
        '                New With {.controller = "", .action = "Index", .topmenu = "Inicio", .id = UrlParameter.Optional},
        '                New With {.controller = New JFControllerListConstraint("Alumnos", "RegistroAcademico"),
        '                          .httpMethod = New HttpMethodConstraint("GET")})

        routes.MapRoute("Route_RegistroAcademico",
                        "{topmenu}/{controller}/{action}/{id}",
                        New With {.controller = "", .action = "Index", .topmenu = "Inicio", .id = UrlParameter.Optional},
                        New With {.controller = New JFControllerListConstraint("Alumnos", "RegistroAcademico", "AnioEscolar", "Profesores", "Periodos", "Home")})

        routes.MapRoute("Route_ProfesoresHome",
                        "Profesores/Inicio",
                        New With {.controller = "Profesores", .action = "Index", .topmenu = "Inicio"})

        routes.MapRoute( _
            "Default", _
            "{controller}/{action}/{id}", _
            New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
        )

    End Sub

    Sub Application_Start()
        AreaRegistration.RegisterAllAreas()

        RegisterGlobalFilters(GlobalFilters.Filters)
        RegisterRoutes(RouteTable.Routes)

        'Activamos la minimizacion de los Scripts del Sistema
        Dim jsBundle = New Bundle("~/Scripts/schoolclick", New JsMinify)
        jsBundle.Include("~/Scripts/jquery-1.7.2.min.js")
        jsBundle.Include("~/Scripts/jquery-ui-1.8.21.custom.min.js")
        jsBundle.Include("~/Scripts/jquery.validate.min.js")
        jsBundle.Include("~/Scripts/jquery.validate.unobtrusive.min.js")
        jsBundle.Include("~/Scripts/Extensions/jquery.validate.unobtrusive.ext.js")
        jsBundle.Include("~/Scripts/Extensions/jquery.jerti-1.0.0.js")
        jsBundle.Include("~/Scripts/jquery.blockUI.js")
        jsBundle.Include("~/Scripts/jquery.gritter.min.js")
        jsBundle.Include("~/Scripts/Extensions/jquey.jerti-autocomplete.js")
        jsBundle.Include("~/Scripts/grid.locale-es.js")
        jsBundle.Include("~/Scripts/jquery.jqGrid.min.js")
        jsBundle.Include("~/Scripts/Extensions/jquery.schoolclick.js")
        BundleTable.Bundles.Add(jsBundle)

        'Activamos la minimizacion de los CSS del sistema
        Dim cssBundle As New Bundle("~/Content/css-schoolclick", New CssMinify)
        cssBundle.IncludeDirectory("~/Content", "*.css", False)
        BundleTable.Bundles.Add(cssBundle)

        'Registramos el ModelMetadataProvider de Jerti para los Metadatos de los Modelos
        ModelMetadataProviders.Current = New JFModelMetadataProvider

        'Registramos nuestros ModelBinder personalizados
        ModelBinders.Binders.Add(GetType(Date), New JFDateModelBinder())
    End Sub
End Class
